package com.manage.project.biz.controller;

import java.util.List;

import com.manage.project.biz.domain.BizShebei;
import com.manage.project.biz.domain.BizSuidao;
import com.manage.project.biz.service.IBizShebeiService;
import com.manage.project.biz.service.IBizSuidaoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.framework.aspectj.lang.annotation.Log;
import com.manage.framework.aspectj.lang.enums.BusinessType;
import com.manage.project.biz.domain.BizJdssrcxc;
import com.manage.project.biz.service.IBizJdssrcxcService;
import com.manage.framework.web.controller.BaseController;
import com.manage.framework.web.domain.AjaxResult;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.framework.web.page.TableDataInfo;

/**
 * 机电设施日常巡查Controller
 *
 * @author liang

 */
@RestController
@RequestMapping("/biz/jdssrcxc")
public class BizJdssrcxcController extends BaseController
{
    @Autowired
    private IBizJdssrcxcService bizJdssrcxcService;
    @Autowired
    private IBizSuidaoService bizSuidaoService;
    @Autowired
    private IBizShebeiService bizShebeiService;

    /**
     * 查询机电设施日常巡查列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:jdssrcxc:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizJdssrcxc bizJdssrcxc)
    {
        startPage();
        List<BizJdssrcxc> list = bizJdssrcxcService.selectBizJdssrcxcList(bizJdssrcxc);
        for (BizJdssrcxc jdssrcxc : list) {
            BizSuidao bizSuidao = bizSuidaoService.selectBizSuidaoById(Long.getLong(jdssrcxc.getField1()));
            if(bizSuidao!=null){
                jdssrcxc.setField1(bizSuidao.getField1());
            }
            BizShebei bizShebei = bizShebeiService.selectBizShebeiById(Long.getLong(jdssrcxc.getField4()));
            if(bizShebei!=null){
                jdssrcxc.setField4(bizShebei.getField2());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出机电设施日常巡查列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:jdssrcxc:export')")
    @Log(title = "机电设施日常巡查", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizJdssrcxc bizJdssrcxc)
    {
        List<BizJdssrcxc> list = bizJdssrcxcService.selectBizJdssrcxcList(bizJdssrcxc);
        ExcelUtil<BizJdssrcxc> util = new ExcelUtil<BizJdssrcxc>(BizJdssrcxc.class);
        return util.exportExcel(list, "机电设施日常巡查数据");
    }

    /**
     * 获取机电设施日常巡查详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:jdssrcxc:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizJdssrcxcService.selectBizJdssrcxcById(id));
    }

    /**
     * 新增机电设施日常巡查
     */
//    @PreAuthorize("@ss.hasPermi('biz:jdssrcxc:add')")
    @Log(title = "机电设施日常巡查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizJdssrcxc bizJdssrcxc)
    {
        String suidaoname=bizJdssrcxc.getField1();
        String shebeicode=bizJdssrcxc.getField12();
        if(bizShebeiService.getByNameAndId(suidaoname,shebeicode)==null){
            return AjaxResult.error("该设备与隧道不匹配"); }

        return toAjax(bizJdssrcxcService.insertBizJdssrcxc(bizJdssrcxc));
    }

    /**
     * 修改机电设施日常巡查
     */
    @Log(title = "机电设施日常巡查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizJdssrcxc bizJdssrcxc)
    {
        String suidaoname=bizJdssrcxc.getField1();
        String shebeicode=bizJdssrcxc.getField12();
        if(bizShebeiService.getByNameAndId(suidaoname,shebeicode)==null){
            return AjaxResult.error("该设备与隧道不匹配"); }

        return toAjax(bizJdssrcxcService.updateBizJdssrcxc(bizJdssrcxc));
    }

    /**
     * 删除机电设施日常巡查
     */
//    @PreAuthorize("@ss.hasPermi('biz:jdssrcxc:remove')")
    @Log(title = "机电设施日常巡查", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizJdssrcxcService.deleteBizJdssrcxcByIds(ids));
    }
}
